/**
 * LogLevel
 *
 * @author Chris Pratt
 *
 * 7/23/2011
 */
package com.anodyzed.onyx.log;

import com.anodyzed.onyx.util.Misc;

public enum LogLevel {
  None, Error, Warn, Info, Debug, Trace, All;

  /**
   * Determine whether the current level is Greater Than or Equal To the 
   * supplied level. 
   *
   * @param level The suspect Log Level
   * @return true if greater or equal
   */
  public boolean isGreaterOrEqual (LogLevel level) {
    return ordinal() <= level.ordinal();
  } //isGreaterOrEqual

  /**
   * Convert the String Level Name to the Log Level.  Return the default Level 
   * if level is null or doesn't match any level names.
   *
   * @param level The Level Name 
   * @param def The Default Level 
   * @return The corresponding or default LogLevel
   */
  public static LogLevel toLevel (String level,LogLevel def) {
    if(!Misc.isEmpty(level)) {
      for(LogLevel lvl : values()) {
        if(level.equalsIgnoreCase(lvl.name())) {
          return lvl;
        }
      }
    }
    return def;
  } //toLevel

  /**
   * Convert the String Level Name to the Log Level
   *
   * @param level The Level Name
   * @return The corresponding LogLevel (or null)
   */
  public static LogLevel toLevel (String level) {
    return toLevel(level,null);
  } //toLevel

} //*LogLevel

